package com.ruoyi.web.controller.his;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.HisOffice;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.service.IHisOfficeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/his/office")
public class HisOfficeController extends BaseController {

  @Autowired private IHisOfficeService officeService;
  private Long deptId;

  /** 获取科室列表 */
  @PreAuthorize("@ss.hasPermi('his:office:list')")
  @GetMapping("/list")
  public TableDataInfo list(HisOffice office) {
    startPage();
    List<HisOffice> list = officeService.selectOfficeList(office);
    return getDataTable(list);
  }

  /** 获取详情 */
  @ApiOperation("门诊详细信息")
  @GetMapping("/{deptId}")
  public AjaxResult getInfo(@PathVariable("deptId") Long deptId) {
    return AjaxResult.success(officeService.queryOfficeById(deptId));
  }

  /** 新增门诊 */
  @ApiOperation("新增门诊")
  @PostMapping
  public AjaxResult add(@RequestBody HisOffice hisOffice) {
    hisOffice.setCreateBy(SecurityUtils.getUsername());
    return toAjax(officeService.insertOffice(hisOffice));
  }

  /** 修改职能监督/办公室监督 */
  @ApiOperation("修改门诊")
  @PutMapping
  public AjaxResult edit(@RequestBody HisOffice hisOffice) {
    hisOffice.setUpdateBy(SecurityUtils.getUsername());
    return toAjax(officeService.updateOffice(hisOffice));
  }

  /** 删除门诊 */
  @ApiOperation("删除门诊")
  @DeleteMapping("/{deptIds}")
  public AjaxResult add(@PathVariable Long[] deptIds) {
    return toAjax(officeService.deleteOfficeByIds(deptIds));
  }

  /** 停诊 */
  @GetMapping("/susmedical/{deptIds}")
  public AjaxResult susMedical(@PathVariable Long[] deptIds) {
    return toAjax(officeService.susmedicalByIds(deptIds));
  }

  /** 开诊 */
  @GetMapping("/recmedical/{deptIds}")
  public AjaxResult resMedical(@PathVariable Long[] deptIds) {
    return toAjax(officeService.recmedicalByIds(deptIds));
  }
}
